<#import "../template.ftl" as t/>
<@t.html ; part>
    <#if part="head">
    </#if>
    <#if part="body">
        <div class="row">
            <div class="panel">
                <div class="panel-heading">
                    <h3 class="panel-title">合同&附件</h3>
                </div>
                <div class="panel-body">
                        <div class="table-responsive">
                            <table class="table table-striped">
                                <thead>
                                    <tr>
                                        <th>序号</th>
                                        <th>文件名称</th>
                                        <th></th>
                                        <th></th>
                                        <th></th>
                                    </tr>
                                </thead>
                                <tr>
                                    <td>1</td>
                                    <td>工商营业执照（加盖公章）</td>
                                    <td><a href="<@spring.url "/resources/files/yyzz.png"/>" target="_blank">样例查看</a></td>
                                    <td><input type="file" id="btn_file" style="display:none">
                                        <button type="button" class="load" value="1">
                                        <#if contractDataMap?? && contractDataMap["1"]??>重传附件<#else>上传附件</#if>
                                        </button>
                                    </td>
                                    <td><a <#if contractDataMap?? && contractDataMap["1"]??>href="${contractDataMap["1"].fileUrl!}" </#if>>查看附件</a></td>
                                </tr>
                                <tr>
                                    <td>2</td>
                                    <td>法人身份证复印件（加盖公章）</td>
                                    <td><a href="<@spring.url "/resources/files/sfz.png"/>" target="_blank">样例查看</a></td>
                                    <td><input type="file" id="btn_file" style="display:none">
                                        <button type="button" class="load" value="7"><#if contractDataMap?? && contractDataMap["7"]??>重传附件<#else>上传附件</#if></button>
                                    </td>
                                    <td><a <#if contractDataMap?? && contractDataMap["7"]??>href="${contractDataMap["7"].fileUrl!}" </#if>>查看附件</a></td>
                                </tr>
                                <tr>
                                    <td>3</td>
                                    <td>电费核查联（每联加盖公章）</td>
                                    <td><a href="<@spring.url "/resources/files/hcl.jpg"/>" target="_blank">样例查看</a></td>
                                    <td><input type="file" id="btn_file" style="display:none">
                                        <button type="button" class="load" value="4"><#if contractDataMap?? && contractDataMap["4"]??>重传附件<#else>上传附件</#if></button></td>
                                    <td><a <#if contractDataMap?? && contractDataMap["4"]??>href="${contractDataMap["4"].fileUrl!}" </#if>>查看附件</a></td>
                                </tr>
                                <tr>
                                    <td>4</td>
                                    <td>《购售电合同》</td>
                                    <td>
                                        <#if contractInfo??>
                                            <#if (contractInfo.planType)?? && contractInfo.planType==1>
                                                <a href="<@spring.url "/resources/files/fcht.docx"/>" target="_blank">标准合同下载</a>
                                            <#elseif (contractInfo.planType)?? && contractInfo.planType==2>
                                                <a href="<@spring.url "/resources/files/qfht.docx"/>" target="_blank">标准合同下载</a>
                                            <#else>
                                                <#if (contractSetting.cooperationType)?? && contractSetting.cooperationType==2>
                                                    <a href="<@spring.url "/resources/files/bdht.docx"/>" target="_blank">标准合同下载</a>
                                                <#else>
                                                    <a href="<@spring.url "/resources/files/fcht.docx"/>" target="_blank">标准合同下载</a>
                                                </#if>
                                            </#if>
                                        </#if>
                                    </td>
                                    <td><input type="file" id="btn_file" style="display:none">
                                        <button type="button" class="load" value="5">
                                        <#if contractDataMap?? && contractDataMap["5"]??>重传附件<#else>上传附件</#if>
                                        </button></td>
                                    <td>
                                        <a <#if contractDataMap?? && contractDataMap["5"]??>href="${contractDataMap["5"].fileUrl!}" </#if>>绑定页查看</a>
                                    </td>
                                </tr>
                                <tr>
                                    <td>5</td>
                                    <td>电力用户信用承诺书（法人签章&公章）</td>
                                    <td><a href="<@spring.url "/resources/files/cns.docx"/>" target="_blank">模板下载</a></td>
                                    <td><input type="file" id="btn_file" style="display:none">
                                        <button type="button" class="load" value="8"><#if contractDataMap?? && contractDataMap["8"]??>重传附件<#else>上传附件</#if></button>
                                    </td>
                                    <td><a <#if contractDataMap?? && contractDataMap["8"]??>href="${contractDataMap["8"].fileUrl!}" </#if>>查看附件</a></td>
                                </tr>
                                <tr>
                                    <td>6</td>
                                    <td>《三方服务协议》</td>
                                    <td><a href="<@spring.url "/resources/files/sfxy.doc"/>" target="_blank">标准合同下载</a></td>
                                    <td><input type="file" id="btn_file" style="display:none">
                                        <button type="button" class="load" value="6">
                                        <#if contractDataMap?? && contractDataMap["6"]??>重传附件<#else>上传附件</#if>
                                        </button></td>
                                    <td><a <#if contractDataMap?? && contractDataMap["6"]??>href="${contractDataMap["6"].fileUrl!}" </#if>>绑定页查看</a></td>
                                </tr>
                            </table>
                        </div>
                    <input type="hidden" name="contractId" id="contractId" value="${(contractInfo.id)!}"/>
                </div>
            </div>
        </div>
    </#if>
    <#if part="modal">
    </#if>

    <#if part="foot_script">
    <script type="text/javascript">
        $('.load').each(function(i){
            var t = $(this).val();
            $(this).after('<input type="file" id="load_img'+t+'" name="file" style="display:none" accept="image/jpg, image/jpeg, image/png, image/bmp" onchange ="uploadFile('+t+')">');
        })
        $('.load').click(function(){
            document.getElementById("load_img"+$(this).val()).click();
        });
        function uploadFile(i) {
            var myform = new FormData();
            var file=$('#load_img'+i)[0].files[0];
            if(!file){
                return false;
            }
            myform.append('file',$('#load_img'+i)[0].files[0]);
            myform.append("types", i);
            myform.append("contractId", $("#contractId").val());
            $.ajax({
                url:'<@spring.url "/contractData/uploadFileData" />',
                type: "POST",
                data: myform,
                contentType: false,
                processData: false,
                success: function (data) {
                    alert(data.message);
                    window.location.reload();
                },
                error:function(data){
                    console.log(data);
                    alert("上传失败！");
                }
            });
        }
    </script>
    </#if>
</@t.html>